package com.designMode.interpreter.terminal;

import com.designMode.interpreter.AbstractExpression;
import com.designMode.interpreter.Context;
import com.designMode.interpreter.TerminalExpression;

/**
 * 变量终结符
 */
public class Variable extends TerminalExpression {
    private String name;

    /**
     * 变量
     *
     * @param name 变量名
     */
    public Variable(String name) {
        this.name = name;
    }

    @Override
    public Object interpret(Context ctx) {
        return ctx.lookup(this);
    }

    @Override
    public boolean equals(AbstractExpression obj) {
        if (obj != null && obj instanceof Variable) {
            return this.name.equals(((Variable) obj).name);
        }
        return false;
    }


    @Override
    public String toString() {
        return name;
    }
}
